# 4）地铁线沿线房屋均价（折线图）【横坐标为地铁几号线，纵坐标为数量】

import pandas as pd
import pyecharts.options as opts
from pyecharts.charts import Line

df = pd.read_excel('data_clean.xlsx')
data2 = df[~df.subway_site.isin([0])]
location_list = []
for location in data2['subway_site']:
    location = location[0:1]
    location_list.append(location)
locations = [location for location in data2.groupby('subway_site').mean()['price'].round(2).items()]

x_data = []
y_data = []
for i in range(len(locations)):
    x_data.append(locations[i][0])
    y_data.append(locations[i][1])

c = (
    Line()
        .add_xaxis(x_data)
        .add_yaxis("房源均价", y_data, is_connect_nones=True)
        .set_global_opts(title_opts=opts.TitleOpts(title="房屋均价"))
        .render("地铁房均价.html")
)
